﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using ControllerLayer.ServiceReferenceCCW;
using DataAccessLayer.PACS;

namespace ControllerLayer.MainView
{
    public class CCWServiceController
    {
        public bool openStudyAtWorkstation(string accessionNumber)
        {
            string studyInstanceUid;
            try
            {
                studyInstanceUid = PACSDataAccess.GetStudyInstanceUID(accessionNumber);
            }
            catch (Exception e)
            {
                return false;
            }            
            ViewerAutomationClient client = new ViewerAutomationClient("ViewerAutomation");

            OpenStudiesRequest studiesRequest = new OpenStudiesRequest();
            studiesRequest.ActivateIfAlreadyOpen = true;
            studiesRequest.StudiesToOpen = new OpenStudyInfo[1];
            studiesRequest.StudiesToOpen[0] = new OpenStudyInfo();
            studiesRequest.StudiesToOpen[0].StudyInstanceUid = studyInstanceUid;
            studiesRequest.StudiesToOpen[0].SourceAETitle = ConfigurationManager.AppSettings["SourceAETitle"].ToString();
            
            client.OpenStudies(studiesRequest);

            return true;
        }
    }
}
